package cn.exrick.xboot.common.timeTask.download;

import cn.exrick.xboot.common.utils.SpringUtils;
import cn.exrick.xboot.common.utils.jiuqi.utils.FileUtile;
import cn.exrick.xboot.modules.ApprovalInfo.service.IApprovalInfoService;
import cn.exrick.xboot.modules.downloadResources.entity.DownloadResources;
import cn.exrick.xboot.modules.downloadResources.service.IDownloadResourcesService;
import cn.exrick.xboot.modules.portalConfig.service.IPortalConfigService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
 * 删除常用下载资源
 */
@Component
@Slf4j
@Data
public class StartDownloadThread implements Runnable {
    private List<DownloadResources> list;
    @Override
    public void run() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Thread.sleep(1000);
            if (list != null && list.size() > 0) {
                log.info("开始删除本地文件资源,time:"+sdf.format(new Date()));
                IPortalConfigService iPortalConfigService = (IPortalConfigService) SpringUtils.getBean("IPortalConfigServiceImpl");
                String path = iPortalConfigService.selectPortalConfigByKey("fileUpdate").getValue();
                for (DownloadResources downloadResources : list) {
                    if (downloadResources.getFileName() != null) {
                        String fileName = downloadResources.getFileName();
                        log.info("要删除的文件名是：" + fileName);
                        boolean b = FileUtile.deleteServerFile(path, fileName);
                        log.info("path:" + path + ","+"fileName:" + fileName);
                        log.info("删除状态：" + b);
                    }
                }
            }
        } catch (Exception e) {
            log.error("删除本地资源失败，Date:" + sdf.format(new Date()));
        }
    }
    public static void main(String[] args) {
        boolean b = FileUtile.deleteServerFile("C://testFile/", "1559009616(1).jpg");
        System.out.println("删除状态：" + b);
    }
}
